<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class User extends CI_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -  
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in 
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see http://codeigniter.com/user_guide/general/urls.html
	 */
	public function __construct()
	{
		parent::__construct();
		$this->load->helper('url');
		$this->load->model('user_mod','us');
		$this->load->library('session');
	}
	 //登录页面
	public function index()
	{
		$this->load->view('login');
	}
	 //登录检测及跳转
	public function checklogin()
	{
		//$this->load->view('login');
		$username=trim($this->input->get_post('username')); //用户名
		$password=trim($this->input->get_post('password')); //密码
		
		if($user_id_car=$this->us->login($username,$password))
		{
				$this->session->set_userdata('u_id', $user_id_car[0]['m_id']); //ci自带的session
				$this->session->set_userdata('username', $user_id_car[0]['m_username']);  //ci自带的session
				$this->session->set_userdata('rank', $user_id_car[0]['rank']);  //ci自带的session
				$this->session->set_userdata('ut_id', $user_id_car[0]['ut_id']);  //ci自带的session
				if($user_id_car[0]['ut_id'] != '' && $user_id_car[0]['ut_id'] != 0){
					header("location:".site_url('task/gettotask_ut'));
				}else{
					header("location:".site_url('task/gettotask'));
				}
		}
		else
		{
			$data['message']="用户名或密码错误";
			$this->load->view('login',$data);
		}	

	}
	 //登录首页
	 public function taskindex()
	 {
		$this->load->view('taskindex');
	 }
	function loginout()
	{
		$this->session->sess_destroy('u_id'); //ci自带的session
		$this->session->sess_destroy('username'); //ci自带的session
		//session_destroy(); //我做的session
		redirect('/user','refresh');
	}
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */